package com.stark.commons.spring.web.support.eureka;

import org.apache.commons.lang3.StringUtils;
import org.springframework.cloud.netflix.eureka.server.event.EurekaInstanceRegisteredEvent;

import lombok.extern.slf4j.Slf4j;

/**
 * 默认的 eureka 服务上线事件处理器。
 * <p>以 <code>WARN</code> 级别打印日志。
 * @author Ben
 * @since 1.0.0
 * @version 1.0.0
 */
@Slf4j
public class DefaultRegisteredEventHandler implements RegisteredEventHandler {

	@Override
	public void handle(EurekaInstanceRegisteredEvent event) {
		if (!event.isReplication()) {
			String instanceId = event.getInstanceInfo().getInstanceId();
			String ipAddr = event.getInstanceInfo().getIPAddr();
			log.warn("服务上线: instanceId={}", ipAddr + ":" + StringUtils.substringAfter(instanceId, ":"));
		}
	}

}
